home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0128.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  1.9 KB  |  67 lines

  1. > --VB--
  2. > SELECT CASE Age
  3. >   CASE < 10
  4. >     print "You are less than 10 years old."
  5. >   CASE = 21
  6. >     print "Hey!! Now you can drink alcohol in the U.S.!!"
  7. >   CASE > 21
  8. >     print "WOW, You're OVER 21!!!"
  9. > END SELECT
  10. > --end--
  11.  
  12. Never tried VB, but in C it's:
  13.    switch(Expression) {
  14.      case Constant:
  15.        Do Your Stuff for this case here;
  16.        break;
  17.      case Constant:
  18.        Do Your Stuff for this case here;
  19.        of course, Your Stuff can extend across many lines,
  20.        being a part of the case up until the "break"
  21.        break;
  22.    }
  23. Interesting that Visual Basic has apparently expanded on the
  24. switch...case style to allow case Expression instead of being limited
  25. to testing for equality.
  26.  
  27. AMOS currently allows you to use the If conditional in a structured
  28. manner:
  29.    If AGE<10 
  30.       Print "You are less than 10 years old."
  31.    End If
  32.    If AGE=21
  33.       Print "Hey!! Now you can drink alcohol in the U.S.!!"
  34.    End If
  35.    If AGE>21
  36.       Print "WOW, You're OVER 21!!!"
  37.    End If
  38.  
  39. As you can see that is very close to the style of your Select Case,
  40. the only drawback being that (in C at least), the switch statement
  41. is faster as it won't check every condition, so the equivalent AMOS
  42. code would be more like:
  43.    If AGE<10 
  44.       Print "You are less than 10 years old."
  45.    Else
  46.       If AGE=21
  47.          Print "Hey!! Now you can drink alcohol in the U.S.!!"
  48.       Else
  49.          If AGE>21
  50.             Print "WOW, You're OVER 21!!!"
  51.          End If
  52.       End If
  53.    End If
  54.  
  55.    This would be exactly the same as your select...case except the
  56.    AMOS code is messier.  Anyway, those are your two current
  57.    choices: clarity with slower execution or messy with faster
  58.    execution.
  59.  
  60.    Looks like AMOS needs support for those Select Cases as they
  61.    give the best of both worlds: clarity and maximum speed. :-)
  62.  
  63.  
  64.                 Garfield Benjamin    e-mail:gbenjam@sosbbs.com
  65.         Website( http://www.sosbbs.com/~gbenjam ): 50% Complete
  66.  
  67.